package com.wc.acwing_sunday.二分.盖楼;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/4/7 11:19
 * @description https://www.acwing.com/problem/content/5569/
 */
public class Main {
    static int n, m, x, y;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        x = sc.nextInt();
        y = sc.nextInt();
        int lca = x * y;
        long l = n + m, r = lca * (long) 1e9;
        while (l < r) {
            long mid = l + r >> 1;
            if (mid - mid / x < n || mid - mid / y < m || mid - mid / lca < m + n) {
                l = mid + 1;
            } else r = mid;
        }
        System.out.println(l);
    }
}
